package com.eobard.utils;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author Eobard_Thawne
 * @version 1.0
 * @date 2022/8/12 -18:01
 */
@Component
public class RedisUtils {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    //存缓存
    public void set(String key ,String value,Long timeOut){
        redisTemplate.opsForValue().set(key,value,timeOut, TimeUnit.SECONDS);
    }

    //取缓存
    public String get(String key){
        return (String) redisTemplate.opsForValue().get(key);
    }

    //清除缓存
    public void del(String key){
        redisTemplate.delete(key);
    }
}
